<template>
  <t-dialog :header="dialogInfo.header" :visible.sync="dialogInfo.visible" :onClose="closeDialog"
    :closeOnOverlayClick="false" :confirmBtn="null" width="80%" top="5%">
    <div style="height: 75vh">
      <t-tabs v-model="value" size="medium">
        <!-- 默认插槽 和 具名插槽（panel）都是用来渲染面板内容 -->
        <t-tab-panel value="1" label="标准化详情">
          <t-form labelWidth="140px" :colon="true">
            <t-row style="align-items: stretch;padding: 10px">
              <t-col :span="6">
                <t-card class="step-card" size="small" title="基本信息">
                  <t-form-item label="标准名称" name="projectName">
                    {{ data.projectName }}
                  </t-form-item>
                  <t-form-item label="联系人" name="linkMan">
                    {{ data.linkMan }}
                  </t-form-item>
                  <t-form-item label="联系方式" name="linkWay">
                    {{ data.linkWay }}
                  </t-form-item>
                  <!-- <t-form-item label="制定或修订" name="formulateType">
                    {{ data.formulateType | filterByDict(dict.type.formulate_type) }}
                  </t-form-item> -->
                  <t-form-item label="制定或修订" name="formulateType">
                    {{ data.formulateType | filterByDict(dict.type.formulate_type)}}
                  </t-form-item>
                  <t-form-item label="被修订标准号" name="reviseNum" v-if="data.formulateType==='2'">
                    {{ data.reviseNum || "-" }}
                  </t-form-item>
                  <t-form-item label="一致性程度" name="consistencyDegree">
                    {{ data.consistencyDegree }}
                  </t-form-item>
                  <t-form-item label="国际标准号" name="internationalStandardNum">
                    {{ data.internationalStandardNum }}
                  </t-form-item>
                  <t-form-item label="主管部门" name="manageDeptId">
                    {{ data.manageDeptId | filterByTree(deptMenuOptions) }}
                  </t-form-item>
                  <t-form-item label="完成时间" name="completeDate">
                    {{ data.completeDate }}
                  </t-form-item>
                  <t-form-item label="申报说明" name="description" >
<!--                    <div v-html="data.description" class="content_style"></div>-->
                    <inner-html :content="data.description"></inner-html>

                  </t-form-item>
                  <t-form-item label="审核状态" name="approveStatus">
                    {{ data.localStandardStatus | filterByDict(dict.type.local_standard_status) }}
                  </t-form-item>
                  <t-form-item label="申报说明" name="approveStatus">
<!--                    <div v-html="data.description"></div>-->
                    <inner-html :content="data.description"></inner-html>

                  </t-form-item>
                </t-card>
              </t-col>
              <t-col :span="6">
                <t-card class="step-card" size="small" title="起草单位">
                  <t-form-item label="起草单位名称" name="draftUnits" v-for="(item) in data.draftUnits" :key="item.unitId">
                    {{ item.unitName }}
                  </t-form-item>
                </t-card>
                <t-card class="step-card" size="small" title="附件信息">
                  <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
                    <template #id="{row, rowIndex}">
                      {{ rowIndex+1 }}
                    </template>
                    <template  #op="{row}">
                      <div v-for="(item,index) in row.fileLists" :key="index">
                        <a class="t-button-link" target="_blank" :href="item.url" >
                          {{item.name}}
                        </a>
                      </div>
                    </template>
                  </t-table>
                </t-card>
              </t-col>
            </t-row>
          </t-form>
        </t-tab-panel>
        <t-tab-panel value="2" label="汇总意见详情">
          <t-table
            rowKey="index"
            :data="data2"
            :columns="columns2"
            style="padding-top: 20px"
          >
            <template  #dealOpinion="{ row }">
              <t-tag :theme="handleTheme(row.dealOpinion,dict.type.deal_opinion)" variant="light" v-if="row.dealOpinion!==''">
                {{row.dealOpinion | filterByDict(dict.type.deal_opinion)}}
              </t-tag>
              <div v-else>
                -
              </div>
            </template>
            <template  #note="{ row }">
              <div v-if="row.note!==''">{{row.note}}</div>
              <div v-else>-</div>
            </template>
            <template  #summary="{ row }">
              <t-tag v-if="row.summary==='1'" theme="success"  variant="light">已汇总</t-tag>
              <t-tag v-else theme="default"  variant="light">未汇总</t-tag>
            </template>
          </t-table>
        </t-tab-panel>
      </t-tabs>
    </div>

  </t-dialog>
</template>

<script>

import {getFiles} from "@/api/common";
import InnerHtml from "@/components/InnerHtml/index.vue";


export default {
  name: "bzhList-detail-dialog",
  dicts:["formulate_type","bzh_approve_type","approve_status","local_standard_status","deal_opinion"],
  components: {
    InnerHtml
  },
  props: {
    dialogInfo: {
      type: Object,
      default() {
        return {
          id: "",
          header: "",
          visible: true
        }
      }
    },
  },
  data() {
    return {
      columns2: [
        {
          colKey: 'chapterNum',
          title: '地方标准章条编号',
          align:"center"

        },
        {
          colKey: 'opinion',
          title: '意见内容',
          align:"center"
        },
        {
          colKey: 'personName',
          title: '提出人',
          align:"center"
        },
        {
          colKey: 'deptName',
          title: '提出单位',
          align:"center"
        },
        {
          colKey: 'summary',
          title: '汇总状态',
          align:"center"
        },
        {
          colKey: 'dealOpinion',
          title: '处理意见',
          align:"center"
        },
        {
          colKey: 'note',
          title: '备注',
          align:"center"
        },
      ],
      data2:[],
      value:"1",
      deptMenuOptions:[],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },
        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      projectFileData: [
        {
          id: 1,
          c1: "立项公文（盖章原件）",
          c2: "是",
          moduleKey: "projectLXGW",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 2,
          c1: "标准草案",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectBZCA"
        },
      ],
      tabValue:"1",
      data: {
        draftUnits:[{}]
      },
    }
  },

  async mounted() {
    await this.getDetail()
    await this.getList()
    await this.getDeptTreeSelect()
  },
  methods: {
    getDeptTreeSelect(){
      return this.$api.system.dept.treeSelectAllIn().then(response=>{
        this.deptMenuOptions = response.data
      }).catch(e=>{
        this.$message.error(e.toString())
      })
    },
    closeDialog() {
      this.$emit("closeBzhDialog", false);
      this.dialogInfo.visible = false
    },
    getList(){
      return this.$api.bzh.opinion.localStandardList({localId:this.dialogInfo.id}).then(res=>{
        this.data2 = res.rows
      }).catch(err=>{
        this.$message.error(err)
      })
    },
    async getDetail(){
      await getFiles(this.dialogInfo.id).then((res) => {
        const files = {}
        res.data.forEach((item) => {
          if (!files[item.moduleKey]) {
            files[item.moduleKey] = []
          }
          files[item.moduleKey].push({
            name: item.fileName,
            url: item.fullFilePath,
            id: item.id,
            filePath: item.filePath
          })
        })
        this.projectFileData[0].fileLists = files.projectLXGW || [];
        this.projectFileData[1].fileLists = files.projectBZCA || [];
        this.projectFileData[0].fileIds = files.projectLXGW?.map(val => val.id) || [];
        this.projectFileData[1].fileIds = files.projectBZCA?.map(val => val.id) || [];

      }).catch((e) => {
        this.$message.error(e.toString());
      });
      await this.$api.bzh.standard.detailById(this.dialogInfo.id).then(response=>{
        this.data = response.data
      })
    },
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 14px;
}
.step-card{
  margin: 10px;
}
.content_style{
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}
</style>
